package com.jx.gn.service;

import cn.hutool.json.JSONUtil;
import com.jx.gn.dao.UserMapper;
import com.jx.gn.entity.user.User;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper  userMapper;


    @Override
    public int saveUser(String carId, WxMpUser wxUser) {
        User user= new User();
        user.setWxId(wxUser.getOpenId());
        user.setCreateTime(new Date());
        user.setWxInfo(JSONUtil.toJsonStr(wxUser));
        user.setIdCard(carId);
        return userMapper.saveUser(user);
    }

    @Override
    public User getUserByWxId(String wxId) {
        return userMapper.getUserByWxId(wxId);
    }
}
